/* Using the HEF4794B LED Driver from Philips * Spec sheet at: * http://webzone.k3.mah.se/projects/arduino-workshop/upload/download.asp?file=51110204007987&enc=False&lang=english * Modified from script at http://arduino.cc/en/Tutorial/LEDDriver * by David Cuartielles, Marcus Hannerstig * * First, some caveats. The board pictured on the site doesn't make clear * that the wiring of the LEDs is from chip to resistor to LED to +V. * To me, it looks like it's the other way around, but it's not. * * Multi 4794s Version 1: Using an Array to set a series of 16 on and off LEDs */ // Setup variables // Pin variables // Description of what pin is connected and what it does: int strobe = 8; // - Strobe output, connected to pin 1 on each 4794 // The Arduino will send a pulse to the Strobe Input on the // 4794 each time all the on's and off's are considered // completed (from coming down the data line). This tells // the 4794 to take the 8 bits stored in its Shift Register // and move them to its Storage Register. // If the Output Enabled pin is set to HIGH, the outputs // (pins 4-7 and 11-14) will reflect the on or off state // that's held in the Storage Register. int data = 9; // - Data output, connected to pin 2 on the first 4794. // The Arduino will send a series of HIGH and LOW outputs // to the 4794, which are stored in the 4794's // 8 Stage Shift Register each time the clock is pulsed. // When the Shift Register is full, it passes the bit // in its last position out the Serial Output (pin 9 or 10). // This allows data to be passed from one 4794 to the next. int clock = 10; // - Clock output, connected to pin 3 on each 4794. // The 4794 uses HIGH and LOW pulses from the Arduino // as a Clock. int eo = 11; // - Output Enable output, referred to as "EO" in the // 4794 docs. Connected to pin 15 on each 4794 // The OE must be HIGH for the LEDs to be on. // LED positions // Second Set First Set // 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 //int myArray[] = {0,1,0,1,0,1,0,1, 0,0,0,1,1,0,0,0}; int myArray[] = {1,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0 }; int arrayLength = 20; // - myArray is a variable for an array which will // correspond to the ons and offs of the LEDs. // The first half of the array will go to the second set // of 8 led's, and the order will go from right to left. int duration = 100; // Standard initializing of pins void setup() { pinMode(data, OUTPUT); pinMode(clock, OUTPUT); pinMode(strobe, OUTPUT); pinMode(eo, OUTPUT); } // Function to pulse the clock void PulseClock(void) { // This function sends a LOW/HIGH/LOW pulse to the 4794 digitalWrite(clock, LOW); // to tell it to take a single bit (a 1 or 0) of info you've delayMicroseconds(40); // set up in the loop. Its sends a pulse something like this: digitalWrite(clock, HIGH); // ..°°°°°. delayMicroseconds(40); // The 4794 looks for the front of the pulse, when it goes from digitalWrite(clock, LOW); // LOW to HIGH, and then accepts the HIGH or LOW input from the } // data pin into its Shift Register. // The Main Loop void loop() { for (int count = 0; count < arrayLength; count++) { // Step thru the values in myArray with count. digitalWrite(data,myArray[count]); // Set the data output pin on the Arduino to 1 or 0, // which is equivalent to HIGH or LOW. // This test is true when we've gone thru all the values in the array. // if (count == arrayLength-1){ digitalWrite(eo, LOW); // Turn off the outputs on the 4794 for a moment. digitalWrite(strobe, HIGH); // Send a HIGH pulse to the Strobe input, which will cause the 4794s // to move the 1's and 0's from the Shift Register to the // Storage Register. PulseClock(); // Tick the clock. digitalWrite(eo, HIGH); // Turn the outputs back on. digitalWrite(strobe, LOW); // Every delay(duration); // } // else { // PulseClock(); // Tick the clock, which tells the 4794 to take in the 1 or 0 // into its Shift Register and be ready for the next one. // } } }